package com.zrx.govern.component.easyexcel.starter.entity;

import com.zrx.govern.component.easyexcel.starter.constants.CommonConstants;
import lombok.*;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.util.Date;

/**
 * 响应信息主体
 *
 * @param <T>
 * @author zhangxiaowei
 */
@ToString
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
public class GovernResult<T> implements Serializable {
    private static final long serialVersionUID = 1L;

    @Getter
    @Setter
    private String status;

    @Getter
    @Setter
    private String message;
    @Getter
    @Setter
    private String error;
    @Getter
    @Setter
    private String path;
    @Getter
    @Setter
    private Date timestamp;

    @Getter
    @Setter
    private T data;

    public static <T> GovernResult<T> ok() {
        return restResult(null, CommonConstants.SUCCESS, "success");
    }

    public static <T> GovernResult<T> ok(T data) {
        return restResult(data, CommonConstants.SUCCESS, "success");
    }

    public static <T> GovernResult<T> ok(String message) {
        return restResult(null, CommonConstants.SUCCESS, message);
    }

    public static <T> GovernResult<T> ok(T data, String message) {
        return restResult(data, CommonConstants.SUCCESS, message);
    }

    public static <T> GovernResult<T> failed() {
        return restResult(null, CommonConstants.FAIL, "fail");
    }

    public static <T> GovernResult<T> failed(String message) {
        return restResult(null, CommonConstants.FAIL, message);
    }

    public static <T> GovernResult<T> failed(T data) {
        return restResult(data, CommonConstants.FAIL, "fail");
    }

    public static <T> GovernResult<T> failed(T data, String message) {
        return restResult(data, CommonConstants.FAIL, message);
    }
    public static <T> GovernResult<T> failed(String status, T data, String message) {
        return restResult(data, status, message);
    }

    public static <T> GovernResult<T> exception(String status, String message) {
        return restResult(null, status, message);
    }

    private static <T> GovernResult<T> restResult(T data, String status, String message) {
        GovernResult<T> apiResult = new GovernResult<>();
        apiResult.setStatus(status);
        apiResult.setData(data);
        apiResult.setMessage(message);
        apiResult.setTimestamp(new Date());
        return apiResult;
    }
}
